class Solution:
    def calPoints(self, operations):
        stack = []
        for op in operations:
            if op == 'C':
                stack.pop()
            elif op == 'D':
                stack.append(2 * stack[-1])
            elif op == '+':
                stack.append(stack[-1] + stack[-2])
            else:
                stack.append(int(op))
        return sum(stack)
if __name__ == '__main__':
    s = Solution()
    operations = ["5","2","C","D","+"]
    print(s.calPoints(operations))